package com.qijian.web.controller.system;

import java.util.List;

import com.qijian.system.domain.ServerResource;
import com.qijian.system.domain.query.ServerQuery;
import com.qijian.system.service.IServerResourceService;
import lombok.RequiredArgsConstructor;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qijian.common.annotation.Log;
import com.qijian.common.core.controller.BaseController;
import com.qijian.common.core.domain.AjaxResult;
import com.qijian.common.enums.BusinessType;
import com.qijian.common.utils.poi.ExcelUtil;
import com.qijian.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
/**
 * 服务器资源Controller
 *
 * @author qijian
 * @date 2023-12-25
 */
@Api(tags = "服务器资源")
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/serverResource")
public class ServerResourceController extends BaseController {

    private final IServerResourceService serverResourceService;

    /**
     * 查询服务器资源列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ServerQuery query, Page<ServerResource> page) {
        initOrderItem(ServerResource.class, page.orders());
        return getDataTable(serverResourceService.page(page, WhereEntityTool.invoke(query)));
    }

    /**
     * 导出服务器资源列表
     */

    @Log(title = "服务器资源" , businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(ServerQuery query, HttpServletResponse response) {
        new ExcelUtil<>(ServerResource. class).exportExcel(response,serverResourceService.list( WhereEntityTool.invoke(query)), "服务器资源数据");
    }

    /**
     * 获取服务器资源详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(serverResourceService.getById(id));
    }

    /**
     * 新增服务器资源
     */
    @Log(title = "服务器资源" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServerResource server) {
        return toAjax(serverResourceService.save(server));
    }

    /**
     * 修改服务器资源
     */
    @Log(title = "服务器资源" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServerResource server) {
        return toAjax(serverResourceService.updateById(server));
    }

    /**
     * 删除服务器资源
     */
    @Log(title = "服务器资源" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(serverResourceService.removeByIds(ids));
    }

}
